<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/9/22 0022
 * Time: 17:26
 */

namespace App\Models;


use Illuminate\Support\Collection;
use PhpParser\ErrorHandler\Collecting;

class GoodsCat extends Model
{
    protected $table      ='yf_goods_cat';
    protected $primaryKey ='cat_id';
    public $timestamps    =false;


    public static function GoodsCat_list(int $cat_parent_id) :Collection
    {
        $dat=self::where('cat_parent_id',$cat_parent_id)
            ->where('cat_name','!=','APP下载' )
            ->get();


        return $dat;
    }

    public static function getChildCat(int $cat_parent_id) :Collection{

        $data=self::where('cat_parent_id',$cat_parent_id)
            ->where('cat_name','!=','APP下载' )
            ->get();
        $datas=array();
        if(!empty($data)){

            $data->each(function ($value,$index) use (&$data) {
                $data[$index]['cat_id'] = $value->cat_id;
                $data[$index]['cat_name'] = $value->cat_name;
                $child =self::from('yf_goods_cat as a')
                    ->select('a.*','b.mb_cat_image')
                    ->leftjoin('yf_mb_cat_image as b','b.cat_id','=','a.cat_id')
                    ->where('a.cat_parent_id',$value->cat_id)
                    ->get();

                $data[$index]['child']    =$child;
            });
        }
        $banner[]=[         //二维数组
            'imags'=>'',
            'url'=>'',
        ];
        $data['banner']=$banner;

        return $data;
    }
}